//
//  DetailMessageViewCell.m
//  LiveSoftware
//
//  Created by lanou3g on 15/7/17.
//  Copyright (c) 2015年 lanou3g. All rights reserved.
//

#import "DetailMessageViewCell.h"
#import "DetailBasketbModel.h"

@interface DetailMessageViewCell ()

/**
 *赛事
 */
@property(nonatomic,strong)UILabel*leagueName;

/**
 *开始时间
 */
@property(nonatomic,strong)UILabel*beginTime;


/**
 *客
 */
@property(nonatomic,strong)UILabel*visitName;


/**
 *主
 */
@property(nonatomic,strong)UILabel *hostName;


/**
 *赛果
 */
@property(nonatomic,strong)UILabel *result;

/**
 *总分
 */
@property(nonatomic,strong)UILabel*score;

/**
 *一共
 */
@property(nonatomic,strong)UILabel *total;






@end


@implementation DetailMessageViewCell



-(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    if(self = [super initWithStyle:style reuseIdentifier:reuseIdentifier])
    {
        
        
        float partX = 0;
        float partY= 0;
        float partHeight = 35;
        
        CGFloat leftWidth = kScreenIp6(80);
        CGFloat rightWidth = kScreenIp6(100);
        CGFloat centerWidth = (kScreenWidth - leftWidth - rightWidth - kScreenIp6(20))/3;
        
        //开始时间
        self.beginTime = [[UILabel alloc]initWithFrame:CGRectMake(partX, partY, leftWidth , partHeight/2)];
        self.beginTime.font = [UIFont systemFontOfSize:11];
        self.beginTime.textAlignment = NSTextAlignmentCenter;
        self.beginTime.text = @"时间";
        self.beginTime.textColor = [UIColor grayColor];
        
        [self.contentView addSubview:_beginTime];
        
        
        
        //赛事
        self.leagueName = [[UILabel alloc]initWithFrame:CGRectMake( partX, partHeight/2, leftWidth, partHeight/2)];
        
        self.leagueName.font = [UIFont systemFontOfSize:11];
        self.leagueName.textAlignment = NSTextAlignmentCenter;
        self.leagueName.text = @"WNBA";
        self.leagueName.textColor = [UIColor grayColor];
        
        [self.contentView addSubview:_leagueName];
        
        
        
        //客
        self.visitName = [[UILabel alloc]initWithFrame:CGRectMake(CGRectGetMaxX(self.beginTime.frame) + kScreenIp6(10), partY, centerWidth, partHeight)];
        self.visitName.font = [UIFont systemFontOfSize:14];
        self.visitName.adjustsFontSizeToFitWidth = YES;
        self.visitName.textAlignment = NSTextAlignmentCenter;
        self.visitName.text = @"梦想";
        
        [self.contentView addSubview:_visitName];
        
        //分数
        self.score = [[UILabel alloc]initWithFrame:CGRectMake(CGRectGetMaxX(self.visitName.frame),partY,centerWidth,partHeight)];
        self.score.font = [UIFont systemFontOfSize:14];
        self.score.adjustsFontSizeToFitWidth = YES;
        self.score.textAlignment = NSTextAlignmentCenter;
        
        self.score.text = @"77:80";
        [self.contentView addSubview:_score];
        
        
        
        
        //主
        self.hostName = [[UILabel alloc]initWithFrame:CGRectMake(CGRectGetMaxX(self.score.frame) ,partY,centerWidth, partHeight)];
        self.hostName.font = [UIFont systemFontOfSize:14];
          self.hostName.textAlignment = NSTextAlignmentCenter;
        self.hostName.text = @"自由";
         self.hostName.adjustsFontSizeToFitWidth = YES;
        
        [self.contentView addSubview:_hostName];
        
        
        
        //赛果
        
        self.result = [[UILabel alloc]initWithFrame:CGRectMake(CGRectGetMaxX(self.hostName.frame) + kScreenIp6(10),partY,rightWidth/2, partHeight)];
        self.result.font = [UIFont systemFontOfSize:14];
        self.result.textAlignment = NSTextAlignmentCenter;
        self.result.text = @"胜";
        
        [self.contentView addSubview:_result];
        
        //总分
        self.total = [[UILabel alloc]initWithFrame:CGRectMake(CGRectGetMaxX(self.result.frame) - kScreenIp6(5),partY,rightWidth/2,partHeight)];
        self.total.font = [UIFont systemFontOfSize:14];
        self.total.textAlignment = NSTextAlignmentCenter;
        
        self.total.text = @"200";
        [self.contentView addSubview:_total];
        
        //线
        UIView *footLineView = [[UIView  alloc]initWithFrame:CGRectMake( 0, partHeight, kScreenWidth, 0.5)];
        
        footLineView.backgroundColor = [UIColor colorWithWhite:0.699 alpha:1.000];
        
        [self.contentView addSubview:footLineView];
        
        
        self.selectionStyle = UITableViewCellSelectionStyleNone;

        
    }
    
    return self;
}

-(void)setCellValueWithModel:(DetailBasketbModel *)model
{
    
    self.leagueName.text = model.leagueName;
    self.beginTime.text = model.beginTime;
    
    self. visitName.text = model.visitName;
    
    self.hostName.text = model.hostName;
    
    self.result.text = model.result;
    self.score.text = model.score;
    self.total.text = model.total;
    
    // 胜红负绿
    NSArray *array = [model.score componentsSeparatedByString:@":"];
    
    if ([model.result isEqualToString:@"胜"])
    {
        if ([array[0] intValue] > [array[1] intValue])
        {
            self.visitName.textColor = [UIColor redColor];
        }
        else
        {
            self.hostName.textColor = [UIColor redColor];
        }
        self.result.textColor = [UIColor redColor];
    }
    else
    {
        if ([array[0] intValue] < [array[1] intValue])
        {
            self.visitName.textColor = [UIColor colorWithRed:0.304 green:0.734 blue:0.177 alpha:1.000];
        }
        else
        {
            self.hostName.textColor = [UIColor colorWithRed:0.304 green:0.734 blue:0.177 alpha:1.000];
        }
        self.result.textColor = [UIColor colorWithRed:0.304 green:0.734 blue:0.177 alpha:1.000];
    }
    
}







@end
